﻿<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../helpproject.xsl" ?>
<topic template="Default" lasteditedby="Geert" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../helpproject.xsd">
  <title translate="true">Using the item templates</title>
  <keywords>
    <keyword translate="true">Item templates</keyword>
    <keyword translate="true">Templates</keyword>
  </keywords>
  <body>
    <header>
      <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Using the item templates</text></para>
    </header>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">There are lots of item templates available for WPF, Silverlight and Windows Phone 7 so it is really easy to develop new views very fast.</text></para>
    <para styleclass="Notes"><text styleclass="Notes" translate="true">To use the templates, simply install the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="SDP_Setup_package" styleclass="Notes" translate="true">Setup package</link></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Difference between logic in view base or behavior</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">As you might have noticed, there are lots of &quot;double&quot; item templates. However, there is a substantial difference between the item templates that implement the logic in the view base or the logic in a behavior.</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">Shortly said, a view with the logic in the view base is defined like this:</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">public</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">class</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">MyView</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">:</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">Catel.Windows.Controls.UserControl</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">{</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> &#160; &#160;</text><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">// rest of the class definition</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">}</text></para>
    <para styleclass="Normal"><text styleclass="Normal" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">This means that the logic for MVVM is located in the view base (in this example, the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_UserControl" styleclass="Normal" translate="true">UserControl</link><text styleclass="Normal" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">).</text></para>
    <para styleclass="Normal"><text styleclass="Normal" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">An item template where the logic is located in a behavior uses regular controls and uses one of the available </text><link displaytype="text" defaultstyle="true" type="topiclink" href="MVVM_behaviors" styleclass="Normal" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">MVVM behaviors</link><text styleclass="Normal" style="font-weight:normal; font-style:normal; color:#000000;" translate="true"> to implement the logic. The behaviors are extremely powerful, but we still recommend the use of logic in the view base since that takes more work out of the hands from the developer.</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">View model</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The view model is the easiest and smallest item template available. The question is even whether a new view model should be created via an item template or by using the </text><text styleclass="Normal" style="font-style:italic;" translate="true">vm</text><text styleclass="Normal" translate="true"> code snippet.</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">User control</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The user control templates create a user control deriving from </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_UserControl" styleclass="Normal" translate="true">UserControl</link><text styleclass="Normal" translate="true">. First it is very important to make a decision whether the logic should be implemented in the view base or a behavior. Then, select the appropriate template:</text></para>
    <para styleclass="Normal"><image src="itemtemplates_usercontrol.png" scale="80.00%" width="764" height="466" styleclass="Image Caption"></image></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The item template will assume that a view model with the same name is already created. For example, if a view with the name </text><text styleclass="Normal" style="font-style:italic;" translate="true">PersonView</text><text styleclass="Normal" translate="true"> is created, the template assumes that the view model name is </text><text styleclass="Normal" style="font-style:italic;" translate="true">PersonViewModel</text><text styleclass="Normal" style="font-style:normal;" translate="true">. If you prefer a different naming convention, simply change the view model type name after the item has been created.</text></para>
    <para styleclass="Notes"><text styleclass="Notes" translate="true">Unfortunately, there is a bug in the item templates system of Visual Studio so it is not possible to also set the namespace of the view models to [ProjectRootNamespace].ViewModels, so this has to be done manually</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Window</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The window templates create a window deriving from </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_DataWindow" styleclass="Normal" translate="true">DataWindow</link><text styleclass="Normal" translate="true">. First it is very important to make a decision whether the logic should be implemented in the view base or a behavior. Then, select the appropriate template:</text></para>
    <para styleclass="Normal"><image src="itemtemplates_window.png" scale="80.00%" width="764" height="466" styleclass="Image Caption"></image></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The item template will assume that a view model with the same name is already created. For example, if a view with the name </text><text styleclass="Normal" style="font-style:italic;" translate="true">PersonView</text><text styleclass="Normal" translate="true"> is created, the template assumes that the view model name is </text><text styleclass="Normal" style="font-style:italic;" translate="true">PersonViewModel</text><text styleclass="Normal" style="font-style:normal;" translate="true">. If you prefer a different naming convention, simply change the view model type name after the item has been created.</text></para>
    <para styleclass="Notes"><text styleclass="Notes" translate="true">Unfortunately, there is a bug in the item templates system of Visual Studio so it is not possible to also set the namespace of the view models to [ProjectRootNamespace].ViewModels, so this has to be done manually</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Page</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">For the few among us that use navigation applications in Silverlight or WPF, there are the page templates. These classes create views based on the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_Page" styleclass="Normal" translate="true">Page</link><text styleclass="Normal" translate="true"> class. There are no separate templates for logic in the view base or logic in the behavior. If this is needed, just let us know!</text></para>
    <para styleclass="Normal"><image src="itemtemplates_page.png" scale="80.00%" width="764" height="466" styleclass="Image Caption"></image></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The item template will assume that a view model with the same name is already created. For example, if a view with the name </text><text styleclass="Normal" style="font-style:italic;" translate="true">PersonView</text><text styleclass="Normal" translate="true"> is created, the template assumes that the view model name is </text><text styleclass="Normal" style="font-style:italic;" translate="true">PersonViewModel</text><text styleclass="Normal" style="font-style:normal;" translate="true">. If you prefer a different naming convention, simply change the view model type name after the item has been created.</text></para>
    <para styleclass="Notes"><text styleclass="Notes" translate="true">Unfortunately, there is a bug in the item templates system of Visual Studio so it is not possible to also set the namespace of the view models to [ProjectRootNamespace].ViewModels, so this has to be done manually</text></para>
  </body>
</topic>
